// import { getCurrentInstance } from '@vue/composition-api';

enum PAKAGE_BASE_PATH {
  PAGES = '/pages',
  OTHER = '/module/other/pages',
  USER = '/module/user/pages',
  DYNAMIC = '/module/dynamic/pages',
  WORD = '/module/word/pages'
}

export const ROUTER_PATHS = {
  MY: `${PAKAGE_BASE_PATH.PAGES}/my/index`,
  LOGIN: `${PAKAGE_BASE_PATH.PAGES}/login/index`,
  HOME: `${PAKAGE_BASE_PATH.PAGES}/HomePage/index`,
  WEBVIEW: `${PAKAGE_BASE_PATH.PAGES}/WebView/index`,
  WORD: `${PAKAGE_BASE_PATH.PAGES}/Word/index`,
  SQUARE: `${PAKAGE_BASE_PATH.PAGES}/Square/index`,
  MESSAGE: `${PAKAGE_BASE_PATH.PAGES}/conversations/conversations`,
  PREFERENCES: `${PAKAGE_BASE_PATH.OTHER}/Preferences/index`,
  PERSONAL: `${PAKAGE_BASE_PATH.USER}/Personal/index`,
  DYNAMIC_DETAIL: `${PAKAGE_BASE_PATH.DYNAMIC}/DynamicDetail/index`,
  PRIVATE_CHAT: `${PAKAGE_BASE_PATH.PAGES}/chat/privateChat/privateChat`,
  CONTACTS: `${PAKAGE_BASE_PATH.PAGES}/contacts/contacts`,
  FANS: `${PAKAGE_BASE_PATH.USER}/Fans/index`,
  WORD_OTHER: `${PAKAGE_BASE_PATH.WORD}/WordOther/index`,
  COLLECTION: `${PAKAGE_BASE_PATH.WORD}/Collection/index`,
  STUDY_HISTORY: `${PAKAGE_BASE_PATH.WORD}/StudyHistory/index`,
  WORD_DETAIL: `${PAKAGE_BASE_PATH.WORD}/WordDetail/index`,
  ERROR_WORDS: `${PAKAGE_BASE_PATH.WORD}/ErrorWords/index`,
  PERSONAL_USER_MESSAGE: `${PAKAGE_BASE_PATH.USER}/Message/index`,
  INVITATION_CODE: `${PAKAGE_BASE_PATH.OTHER}/InvitationCode/index`,
  DYNAMIC_PUBLISH: `${PAKAGE_BASE_PATH.DYNAMIC}/DynamicPublish/index`
};

export const useRouter = () => {
  // const current = getCurrentInstance();
  // console.log(current);
  return {
    navigateTo: (
      config: UniApp.NavigateToOptions & {
        params?: Record<string, any>;
      }
    ) => {
      if (config.params && typeof config.params === 'object') {
        Object.keys(config.params).forEach((key, index) => {
          const value =
            typeof config.params?.[key] === 'object' ? JSON.stringify(config.params?.[key]) : config.params?.[key];
          if (index === 0) {
            config.url += `?${key}=${value}`;
          } else {
            config.url += `&${key}=${value}`;
          }
        });
      }
      return uni.navigateTo({
        animationType: 'zoom-fade-out',
        animationDuration: 300,
        ...config
      });
    },
    navigateBack: (config: UniApp.NavigateBackOptions) => {
      return uni.navigateBack(config);
    },
    switchTab: (config: UniApp.SwitchTabOptions) => {
      return uni.switchTab(config);
    }
  };
};

export const useRoute = () => {};
